<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>销售退货订单入库确认</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){
        var saleReturnedId = new Ext.form.Hidden({
          name: 'sale_returned_id',
          value: '<%=params[:id]%>'
        });
        
        var warehouseTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{number}|{name}', '</div></tpl>');
        var warehouseStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/warehouse/getAllWarehouse?for_cbb=true"
          }),
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'number'
            }, {
              name: 'name'
            }])
        });
        
        var warehouse =  new Ext.form.ComboBox({
          fieldLabel: '退货入库仓库',
          store: warehouseStore,
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'warehouse_id',
          //typeAhead: false,
          loadingText: '搜索中...',
          width:140,
          allowBlank: false,
          //pageSize: 10,
          //hideTrigger: false,
          tpl: warehouseTemplate,
          minChars: 0,
          itemSelector: 'div.search-item',
          triggerAction:"all",
          editable:false,
          selectOnFocus:true
        });

        //实际退货入库日期
        var actionDate = new Ext.form.DateField({
          fieldLabel: '入库日期',
          allowBlank: false,
          name: 'action_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          blankText: "入库日期必须选择",
          emptyText: '入库日期...'
          //anchor: '50%'
        });
        
        //提交按钮
        var submitButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            submitButton.setDisabled(true);
            if (returnedEntryConfirmFormPanel.form.isValid()) {
              returnedEntryConfirmFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    returnedEntryWin.destroy();
                  } else {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: resp.result.info,
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.WARNING
                    });                    
                  }
                  submitButton.enable();
                },
                failure: function(result, request){
                  submitButton.enable();
                  Ext.MessageBox.show({
                    title: '消息',
                    msg: "通讯失败，请从新操作",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                }
              });
            }
            else {
              submitButton.enable();
              
            }
          }
        })
        
        var returnedEntryConfirmFormPanel = new Ext.form.FormPanel({
          labelWidth: 80,
          width: '290',
          labelAlign: 'right',
          frame : true,
          url: '/sale_returned/entryFinish',
          method: 'GET',
          items: [saleReturnedId,warehouse,actionDate],
          buttons: [submitButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                returnedEntryWin.destroy();
              }
            }]
        });
        returnedEntryConfirmFormPanel.render('sale_returned_confirm_form');
      })
    </script>
    <div id="sale_returned_confirm_form"></div>
  </body>
</html>
